package main

import (
	"gin-study/pkg/api"
	"gin-study/pkg/middleware"

	"github.com/gin-gonic/gin"
)

func main() {
	router := gin.Default()

	// LoadHTMLGlob() 用于加载模板文件
	router.LoadHTMLGlob("templates/**/*")

	communicateRouter := router.Group("/communicate")
	{
		communicateAPI := &api.CommunicateAPI{}
		communicateRouter.GET("/hello", communicateAPI.Hello)
		communicateRouter.GET("/goodbye", communicateAPI.GoodBye)
	}

	renderHtmlRouter := router.Group("/renderHtml")
	{
		renderHtmlAPI := &api.RenderHtmlAPI{}
		renderHtmlRouter.GET("/singlestring", renderHtmlAPI.SingleString)
		renderHtmlRouter.GET("/singlestruct", renderHtmlAPI.SingleStruct)
		renderHtmlRouter.GET("/basearrayslice", renderHtmlAPI.BaseArraySlice)
		renderHtmlRouter.GET("/structarrayslice", renderHtmlAPI.StructArraySlice)
		renderHtmlRouter.GET("/map", renderHtmlAPI.Map)
		renderHtmlRouter.GET("/multistruct", renderHtmlAPI.MultiStruct)
	}

	paramRouter := router.Group("/param")
	{
		paramAPI := &api.ParamAPI{}
		paramRouter.GET("/stringquery", paramAPI.StringQuery)
		paramRouter.GET("/stringarrayquery", paramAPI.StringArrayQuery)
		paramRouter.GET("/pathparam/:name/:age", paramAPI.PathParam)
		paramRouter.POST("/bodyform", paramAPI.BodyForm)
		paramRouter.POST("/bind", paramAPI.Bind)
		paramRouter.POST("/bind/:name/:age", paramAPI.BindUri)
	}

	middlerWareRouter := router.Group("/middleware")
	middlerWareRouter.Use(middleware.Middleware1())
	middlerWareRouter.Use(middleware.Middleware2())
	middlerWareRouter.Use(middleware.Middleware3())
	{
		middleWareApi := &api.MiddleWareAPI{}
		middlerWareRouter.GET("/test", middleWareApi.TestMiddleWare)
		middlerWareRouter.GET("/chain", middleWareApi.BusinessHandle)
	}

	router.Run(":9090") // 指定服务监听 9090 端口
}
